import type { ExtractPropTypes, PropType } from 'vue'

export type VirtualListLayoutGap = number | [columnGap: number, rowGap: number]

export interface VirtualListLayout {
  itemHeight: number
  itemWidth: number
  overscan?: number
  gap?: VirtualListLayoutGap
}

export type VirtualListDataSource<T = unknown> = Record<string, T> | T[]

export type VirtualListProps<T = unknown> = {
  layout: VirtualListLayout
  dataSource: VirtualListDataSource<T>
}

export interface VirtualListFinalData <T = unknown> {
  data: T
  key: string
}

export function normalizeLayout(layout: VirtualListLayout) {
  const { itemHeight, itemWidth, overscan, gap } = layout
  const [columnGap, rowGap] = Array.isArray(gap) ? gap : typeof gap === 'number' ? [gap, gap] : [0, 0]
  return { itemHeight, itemWidth, columnGap, rowGap, overscan: overscan ?? 5 }
}
